/**
 * 分类
 */

const express = require("express");
const { body } = require("express-validator");
const {
  selectCategoryList,
  insertCategory,
  deleteCategory,
  updateCategory,
} = require("@root/services/blog/category.service.js");

const router = express.Router();

/**
 * 获取分类
 */
router.get("/", selectCategoryList);

/**
 * 添加分类
 */
router.post(
  "/",
  [
    body("cate_name").notEmpty().escape().withMessage("分类名不能为空"),
    body("cate_name").isLength({ max: 6 }).withMessage("分类名不能超过6个字符"),
  ],
  insertCategory
);

/**
 * 删除分类
 */
router.delete(
  "/",
  [
    body("ids").isArray({ min: 1 }).withMessage("ids必须是数组,且不能为空"),
    body("ids.*").isInt({ min: 1 }).withMessage("数组中的元素必须是正整数"),
  ],
  deleteCategory
);

/**
 * 修改分类
 */
router.put(
  "/",
  [
    body("cate_id").notEmpty().withMessage("分类id不能为空"),
    body("cate_name").notEmpty().withMessage("分类名不能为空"),
  ],
  updateCategory
);

module.exports = router;
